<?php

namespace Web;

//! Url plug-in
class Url extends \Prefab {

	/**
     *  Use this function to parse out the query array element from 
     *  the output of parse_url(). 
     *	@return array
     *	@param $url string
     **/
	public function parseQuery($url) {
        $arr  = array(); 
        $url = parse_url($url, PHP_URL_QUERY); 
        if ($url != null && $url != '') {
            $var  = html_entity_decode($url);
            $var  = explode('&', $var); 
            foreach($var as $val) 
            { 
                $x          = explode('=', $val); 
                $arr[$x[0]] = $x[1]; 
            } 

            unset($val, $x, $var); 
        }

        return $arr; 
    }


    /**
     * Use this function to generate the breadcrumbs with the google markup
     * supported.
     * @return string
     * @param $links array
     */

    public function generateBreadcrumbs($links = array()) {

        $result = '<div id="b-container" xmlns:v="http://rdf.data-vocabulary.org/#">
<ul class="breadcrumb" itemprop="breadcrumb">';
        if (count($links) >0) {
            for($i=0; $i< count($links);$i++) {
                $html = '<li class="bcrumb-'.($i+1).'" typeof="v:Breadcrumb"';
                if ($i == count($links) -1)
                    $html .= ' class="active"';
                
                $html .= '><a href="'.$links[$i]["href"].'" title="'.$links[$i]['text'].'" rel="v:url" property="v:title">'.$links[$i]["text"].'</a>';
                $result .= $html;
                if ($i < count($links) -1)
                    $result .='<span class="divider">/</span>';
                $result .= "</li>";
            }
        }

        $result .= "</ul></div>";

        return $result;
    }
}
